package com.yangxc.core.datasource.config;

import com.baomidou.dynamic.datasource.provider.DynamicDataSourceProvider;
import com.yangxc.core.datasource.properties.DataSourceProperties;
import com.yangxc.core.datasource.provider.JdbcDynamicDataSourceProvider;
import lombok.AllArgsConstructor;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yangxc
 * @version 1.0.0
 * @ClassName DynamicDataSourceAutoConfig.java
 * @Description TODO
 * @createTime 2021年07月21日 17:09:00
 */
@Configuration
@AllArgsConstructor
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
@EnableConfigurationProperties(DataSourceProperties.class)
public class DynamicDataSourceAutoConfig {

    private final DataSourceProperties dataSourceProperties;

    private final StringEncryptor stringEncryptor;

    @Bean
    public DynamicDataSourceProvider dynamicDataSourceProvider(){
        return new JdbcDynamicDataSourceProvider(dataSourceProperties,stringEncryptor);
    }
}
